package common.log;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

import common.props.ProjProps;

public class WindLog {

	private static WindLog wl = new WindLog();
	private Logger theLog;

	private WindLog() {
		theLog = Logger.getLogger("WindDisplayLog");
		Handler fh;
		try {
			fh = new FileHandler("winddisplay.log", 100000, 2);
			fh.setFormatter(new SimpleFormatter());
			theLog.addHandler(fh);
			setLevel();
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	private void setLevel() {
		String lev = null;
		try {
			lev = ProjProps.getProp(ProjProps.LOG_LEVEL);
			if (lev != null)
				theLog.setLevel(Level.parse(lev));
			else
				theLog.setLevel(Level.INFO);
		} catch (Exception e) {
			theLog.setLevel(Level.INFO);
		}

	}

	public void logInfo(String msg) {
		theLog.info(msg);
	}

	public void logWarning(String msg) {
		theLog.warning(msg);
	}

	public void logSevere(String msg) {
		theLog.severe(msg);
	}
	
	public static WindLog getLogger() {
		return wl;
	}
}
